//
//  WSBaseController.swift
//  微博
//
//  Created by 武莎莎 on 15/9/6.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class WSBaseController: UITableViewController {
    
    var visitView:WSVisitView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    override func loadView() {
        
        WSUserAccountViewModel.sharedUserAccount.isLogin ? super.loadView() : setUpVisitView()
    }
    
    private func setUpVisitView(){
        // 替换tableView的根视图
        visitView = WSVisitView()
        view = visitView
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerClicked")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClicked")
        
        visitView?.loginBtn.addTarget(self, action: "loginClicked", forControlEvents: UIControlEvents.TouchUpInside)
        visitView?.registerBtn.addTarget(self, action: "registerClicked", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    func loginClicked(){
        let nav = UINavigationController(rootViewController: WSOAuthController())
        presentViewController(nav, animated: true, completion: nil)
    }
    func registerClicked(){
        print("注册")
    }
}
